package cz.kfad.ofrss.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseOpenHelper extends SQLiteOpenHelper {

    private static final int DATABASE_VERSION = 1;
	private static final String DATABASE_NAME = "cz.kfad.ofrss.database9";

    public DatabaseOpenHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {

        String createRssFeedTable = "CREATE TABLE " + DbConstants.TABLE_RSS_FEED + "( " +
                DbConstants.COLUMN_RSS_FEED_ID + " INTEGER PRIMARY KEY AUTOINCREMENT ," +
                DbConstants.COLUMN_RSS_FEED_CHANNEL_ID + " INTEGER ," +
                DbConstants.COLUMN_RSS_FEED_READ + " INTEGER ," +
                DbConstants.COLUMN_RSS_FEED_TITLE + " TEXT ," +
                DbConstants.COLUMN_RSS_FEED_URL + " TEXT ," +
                DbConstants.COLUMN_RSS_FEED_PUBDATE + " INTEGER ," +
 DbConstants.COLUMN_RSS_FEED_TEXT + " TEXT ,"
				+ DbConstants.COLUMN_RSS_FEED_CONTENT_ATTEMPTS + " INTEGER ," + DbConstants.COLUMN_RSS_FEED_CONTENT + " TEXT " +
                ");";

        db.execSQL(createRssFeedTable);

        String createChannelTable = "CREATE TABLE " + DbConstants.TABLE_CHANNEL + "( " +
                DbConstants.COLUMN_CHANNEL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT ," +
                DbConstants.COLUMN_CHANNEL_NAME + " TEXT ," +
                DbConstants.COLUMN_CHANNEL_URL + " TEXT ," +
                DbConstants.COLUMN_CHANNEL_NEWEST_FETCHED + " TEXT ," +
                DbConstants.COLUMN_CHANNEL_TOTAL_FEEDS + " INTEGER ," +
                DbConstants.COLUMN_CHANNEL_UNREAD_FEEDS + " INTEGER " +
                ");";

        db.execSQL(createChannelTable);

        String createCategoryTable = "CREATE TABLE " + DbConstants.TABLE_CATEGORY + "( " +
                DbConstants.COLUMN_CATEGORY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT ," +
                DbConstants.COLUMN_CATEGORY_NAME + " TEXT ," +
                DbConstants.COLUMN_CATEGORY_KEY + " TEXT ," +
                DbConstants.COLUMN_CATEGORY_TOTAL_FEEDS + " INTEGER ," +
                DbConstants.COLUMN_CATEGORY_UNREAD_FEEDS + " INTEGER " +
                ");";

        db.execSQL(createCategoryTable);

        String createCategoryFeedTable = "CREATE TABLE " + DbConstants.TABLE_CATEGORY_FEED + "( " +
                DbConstants.COLUMN_CATEGORY_FEED_CATEGORY_ID + " INTEGER ," +
                DbConstants.COLUMN_CATEGORY_FEED_FEED_ID + " INTEGER " +
                ");";

        db.execSQL(createCategoryFeedTable);

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
